package eu.goldenak.ircbot.module;

import eu.goldenak.ircbot.BotGroup;
import eu.goldenak.ircbot.BotManager;
import eu.goldenak.ircbot.BotTimer;
import eu.goldenak.ircbot.IrcBot;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * This module was used to test the new timer functionalities. I decided not to
 * delete it, since it contains a bit of documentation on how to use BotTimers.
 */
public class TestModule extends ModuleBase {
	
	/**
	 * When we successfully connect to the IRC server, we register our BotTimer.
	 * Of course, this can be done in the constructor as well. Or any other
	 * place you fancy.
	 */
	public void onConnect (IrcBot pBot) {
		// I used the Calendar functionality from the Java API for quick testing.
		GregorianCalendar pCal = new GregorianCalendar ();
		pCal.add (Calendar.MINUTE, 1);
		
		/**
		 * And this is how you register a BotTimer. As you can see, you can use
		 * the constructors in the BotTimer class to specify the time and/or 
		 * interval of execution.
		 * 
		 * Another use of the constructor could be:
		 * new BotTimer (10000, true) {...};
		 * This will repeat the BotTimer every 10 seconds.
		 */
		new BotTimer (pCal.getTime ()) {
			
			/**
			 * The run method will be called every time the BotTimer is 
			 * scheduled to run. In this case, we'll be spamming a channel.
			 */
			public void run () {
				System.out.println ("Running.");
				BotGroup pBots = BotManager.getInstance ().getBots ().getBotsInChannel ("#LVP.CoD.echo");
				
				for (IrcBot pBot : pBots) {
					pBot.out.privmsg ("#LVP.CoD.echo", "What's up?");
				}
			}
		};
	}
}